package com.qili.controller;

import com.qili.annotation.TokenCheck;
import com.qili.core.utils.DictTypes;
import com.qili.core.utils.DictUtil;
import com.qili.entity.base.BaseCompany;
import com.qili.entity.base.BaseDict;
import com.qili.entity.zx.dto.ZxProjectDTO;
import com.qili.service.base.BaseCompanyService;
import com.qili.service.base.BaseDictService;
import com.qili.util.JsonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zengyuli
 * @date 2021/9/29
 * @description
 */
@Controller
@RequestMapping("/app/dict")
public class AppDictController {
    @Autowired
    private BaseDictService baseDictService;
    @Autowired
    private BaseCompanyService baseCompanyService;

    @ApiOperation(value = "/selectDicByCode", httpMethod = "GET", notes = "查询字典")
    @PostMapping(value = "selectDicByCode")
    @ResponseBody
    @TokenCheck
    public JsonUtil selectDicByCode(@RequestBody BaseDict  baseDict) {
        String codeliststr = baseDict.getBadtCode();
        if(StringUtils.isBlank(codeliststr)){
            JsonUtil.error("参数获取失败");
        }
        HashMap  map=new HashMap();
        String[] split = codeliststr.split(",");
        for (int i = 0; i <split.length ; i++) {
            String code=split[i];
            List<BaseDict> AlstHyType = DictUtil.getDictByTypeApp(code);
            map.put(code,AlstHyType);
        }

        return JsonUtil.sucessWithData("返回成功", map);
    }

    /*
     * 获取业务类型
     */
    @ApiOperation(value = "/getYw", httpMethod = "GET", notes = "注册")
    @PostMapping(value = "getYw")
    @ResponseBody
    @TokenCheck
    public JsonUtil getYw(@RequestBody BaseDict  baseDict) {
        String code = baseDict.getBadtCode();
        JsonUtil reJs = new JsonUtil();
        try {
            List<BaseDict> list = baseDictService.selectYw(code);
            reJs.setMsg("获取成功。");
            reJs.setFlag(true);
            reJs.setData(list);
            return reJs;

        } catch (Exception e) {
            e.printStackTrace();
            reJs.setMsg("获取失败！！" + e.getMessage());
            reJs.setFlag(false);
            return reJs;
        }
    }



    /*项目类型*/
    List<BaseDict> projectTypeList = DictUtil.getDictByType(DictTypes.PROJECT_TYPEZX);


    @ApiOperation(value = "/selectProjectOwner", httpMethod = "GET", notes = "监理项目归属")
    @GetMapping(value = "selectProjectOwner")
    @ResponseBody
    @TokenCheck
    public JsonUtil selectProjectOwner() {
        List<Map<String, Object>> company = baseCompanyService.selectProjectOwner();
        return JsonUtil.sucessWithData("项目归属返回成功", company);
    }

    // 供需项目类型
    @ApiOperation(value = "/selectSupplierType", httpMethod = "GET", notes = "供需项目类型")
    @GetMapping(value = "selectSupplierType")
    @ResponseBody
    @TokenCheck
    public JsonUtil selectSupplierType() {
        List<BaseDict> list = baseDictService.selectSupplierType();
        return JsonUtil.sucessWithData("项目类型返回成功", list);
    }



}
